﻿/*
Commerce by Onex – eCommerce software platform (www.ecommerce.byonex.com)
Copyright (C) 2008-2010 by Onex Group

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
*/
function SetAll(sender) {
    re1 = new RegExp('RowCb');
    re2 = new RegExp('btnPerformAction');
    re3 = new RegExp('btnAdressListCSV');
    re4 = new RegExp('btnAdressStickers');
    re5 = new RegExp('btnAdressList');
    re6 = new RegExp('btnInvoices');

    for (i = 0; i < document.forms[0].elements.length; i++) {
        elm = document.forms[0].elements[i];
        if (elm.type == 'checkbox') {
            if (re1.test(elm.name))
                elm.checked = sender.checked;
        } else if (elm.type == 'submit' || elm.type == 'button') {
            if (re2.test(elm.name))
                elm.disabled = !sender.checked;
            else if (re3.test(elm.name))
                elm.disabled = !sender.checked;
            else if (re4.test(elm.name))
                elm.disabled = !sender.checked;
            else if (re5.test(elm.name))
                elm.disabled = !sender.checked;
            else if (re6.test(elm.name))
                elm.disabled = !sender.checked;
        }
    }
}

function Select() {
    re1 = new RegExp('RowCb');
    re2 = new RegExp('SetAll');
    re3 = new RegExp('btnPerformAction');
    re4 = new RegExp('btnAdressListCSV');
    re5 = new RegExp('btnAdressStickers');
    re6 = new RegExp('btnAdressList');
    re7 = new RegExp('btnInvoices');
    all = true;
    none = true;

    for (i = 0; i < document.forms[0].elements.length; i++) {
        elm1 = document.forms[0].elements[i];
        if (elm1.type == 'checkbox') {
            if (re2.test(elm1.name)) {
                cbSetAll = elm1;
            }
            else {
                if (re1.test(elm1.name))
                    if (elm1.checked == false) {
                    all = false;
                } else if (elm1.checked == true) {
                    none = false;
                }
            }
        } else if (elm1.type == 'submit' || elm1.type == 'button') {
            if (re3.test(elm1.name)) {
                btnPerformAction = elm1;
            } else if (re4.test(elm1.name)) {
                btnAdressListCSV = elm1;
            } else if (re5.test(elm1.name)) {
                btnAdressStickers = elm1;
            } else if (re6.test(elm1.name)) {
                btnAdressList = elm1;
            } else if (re7.test(elm1.name)) {
                btnInvoices = elm1;
            }
        }
    }
    cbSetAll.checked = all;
    btnPerformAction.disabled = none;
    btnAdressListCSV.disabled = none;
    btnAdressStickers.disabled = none;
    btnAdressList.disabled = none;
    btnInvoices.disabled = none;
}


function GenerateAdressStickers() {
    re = new RegExp('RowCb');
    selectedIDs = '';

    for (i = 0; i < document.forms[0].elements.length; i++) {
        elm = document.forms[0].elements[i];
        if (elm.type == 'checkbox')
            if (re.test(elm.name))
            if (elm.checked == true) {
            tab = elm.value.split('_');
            selectedIDs += tab[0] + ',';
        }
    }
   // var offset = $('#orderOptions input[@name^=Offset]').val();
    var offset = $('#txtOffset').val();
    if (selectedIDs != '') {
        window.open('ReportView.ashx?ReportType=AdressSticker&RealizationIDs=' + selectedIDs + '&Offset=' + offset);
    }

}

function GenerateAdressList() {
    re = new RegExp('RowCb');
    selectedIDs = '';

    for (i = 0; i < document.forms[0].elements.length; i++) {
        elm = document.forms[0].elements[i];
        if (elm.type == 'checkbox')
            if (re.test(elm.name))
            if (elm.checked == true) {
            tab = elm.value.split('_');
            selectedIDs += tab[0] + ',';
        }
    }

    tbp = document.getElementById('tbParcelNumber');
    if ((selectedIDs != '') && (!isNaN(parseInt(tbp.value))))
        window.open('ReportView.ashx?ReportType=AdressList&StartNr=' + parseInt(tbp.value) + '&RealizationIDs=' + selectedIDs);
}


function GenerateAdressListCSV() {
    re = new RegExp('RowCb');

    selectedIDs = '';

    for (i = 0; i < document.forms[0].elements.length; i++) {
        elm = document.forms[0].elements[i];
        if (elm.type == 'checkbox')
            if (re.test(elm.name))
            if (elm.checked == true) {
            tab = elm.value.split('_');
            if (tab[1] == '1')
                selectedIDs += tab[0] + ',';
        }
    }
    if (selectedIDs != '')
        window.open('ReportView.ashx?ReportType=AdressListCSV&RealizationIDs=' + selectedIDs);
}

function GenerateInvoices() {
    var control = $('#ddlInvoiceType');
    //var control = document.getElementById('ctl00$cphMain$ddlInvoiceType');
    var value = control.value //control.getAttribute("value");
    var invoiceType = '';
    switch (value) {
        case '1': invoiceType = 'Oryginal'; break;
        case '2': invoiceType = 'Kopia'; break;
        case '3': invoiceType = 'Oryginal+Kopia'; break;
        case '4': invoiceType = 'Proforma'; break;
        default: invoiceType = 'Oryginal+Kopia';
    }
    re = new RegExp('RowCb');

    selectedIDs = '';

    for (i = 0; i < document.forms[0].elements.length; i++) {
        elm = document.forms[0].elements[i];
        if (elm.type == 'checkbox')
            if (re.test(elm.name))
            if (elm.checked == true) {
            tab = elm.value.split('_');
            selectedIDs += tab[0] + ',';
        }
    }
    if (selectedIDs != '')
        window.open('ReportView.ashx?ReportType=MultiInvoice&InvoiceType=' + invoiceType + '&RealizationIDs=' + selectedIDs);
}
